import request from '@/utils/http.js'
export default {
	login(data) {
	  return request({
	    url: '/user/login',
	    method: 'POST',
	    data: data,
		showLoading: true,
	  })
	},
	 // 查询用户信息
select() {
        return request({
            url: '/user/select',
            method: 'GET',
            showLoading: true
        })
    },

// 修改账号信息的方法
updateAccountInfo(data) {
    return request({
        url: '/user/update',  // 确保这个接口路径是正确的
        method: 'POST',
        data: data,
        showLoading: true
    })
},
 // 上传头像
    uploadAvatar(filePath) {
        if (!filePath) {
            return Promise.reject(new Error('文件路径不能为空'))
        }
        return new Promise((resolve, reject) => {
            uni.uploadFile({
                url: 'http://localhost:8080/image/upload',
                filePath: filePath,
                name: 'file',
                header: {
                    'token': uni.getStorageSync('token')
                },
                success: (uploadRes) => {
                    try {
                        const data = JSON.parse(uploadRes.data)
                        if (data.code === 1) {
                            resolve(data)
                        } else {
                            reject(new Error(data.msg || '上传失败'))
                        }
                    } catch (e) {
                        reject(new Error('响应格式错误'))
                    }
                },
                fail: (err) => {
                    reject(new Error(err.errMsg || '上传失败'))
                }
            })
        })
    },

	  
		
	
	  
	  
	  
	  
	register(data) {
	  return request({
	    url: '/user/user/getall',
	    method: 'GET',
	    data: data,
			showLoading: true,
	  })
	},
	
	logout(data) {
	  return request({
	    url: '/user/logout',
	    method: 'POST',
	    data: data,
			showLoading: true,
	  })
	},
	
	
}




